﻿using Panuon.UI.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text.Json;
using System.Windows.Controls;
using System.Windows.Input;
using WaveringLand_Launcher.Helper;
using WaveringLand_Launcher.Helper.Common;
using WaveringLand_Launcher.Model;
using WaveringLand_Launcher.View;

namespace WaveringLand_Launcher.ViewModel
{
    [PropertyChanged.AddINotifyPropertyChangedInterface]
    public class MainWindowViewModel
    {
        public ICommand TipBtnCommand { get; set; }   
        public bool DrawerOpen { get; set; } = false;
        public UserControl Control { get; set; } = new LaunchView();

        public MainWindowViewModel()
        {
            TipBtnCommand = new RelayCommand(TipBtnClick);
        }

        void TipBtnClick(object sender)
        {
            TipHelper.ShowRandomTipWindow();
        }
        public bool CheckResources()
        {
            List<string> LostFiles = new();
            //Get index.json
            //Combine index path
            List<WllFile> Files = new();
            foreach (var item in Files)
            {
                var apath = Path.Combine(Directory.GetCurrentDirectory(), ".minecraft", item.Path);

                if (File.Exists(apath))
                {

                    if(Md5Helper.GetMd5(apath) == item.MD5)
                    {
                        continue;
                    }
                }

                LostFiles.Add(item.Url);
            }
            return LostFiles.Count == 0;
        }
    }
}